package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsGrouponMapper;
import com.qf.mapper.DtsGrouponRulesMapper;
import com.qf.pojo.DtsGroupon;
import com.qf.pojo.DtsGrouponRules;
import com.qf.pojo.DtsTopic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

@Service
public class GrouponServiceImpl implements GrouponService{
    @Autowired
    private DtsGrouponRulesMapper dtsGrouponRulesMapper;

    @Override
    public IPage<DtsGrouponRules> selectPage(int page, int limit, String sort, String order, Integer goodsId) {
        QueryWrapper<DtsGrouponRules> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(!StringUtils.isEmpty(goodsId),"goods_id",goodsId);
        queryWrapper.orderBy(!StringUtils.isEmpty(sort),"asc".equalsIgnoreCase(order),sort);

        return dtsGrouponRulesMapper.selectPage(new Page<DtsGrouponRules>(page,limit),queryWrapper);
    }

    @Override
    public void creat(DtsGrouponRules grouponRules) {
        grouponRules.setAddTime(new Date());
        grouponRules.setGoodsName("111");
        dtsGrouponRulesMapper.insert(grouponRules);
    }

    @Override
    public void update(DtsGrouponRules grouponRules) {
        grouponRules.setUpdateTime(new Date());
        grouponRules.setGoodsName("111");
        dtsGrouponRulesMapper.updateById(grouponRules);
    }

    @Override
    public void delete(DtsGrouponRules grouponRules) {
        dtsGrouponRulesMapper.deleteById(grouponRules);
    }
}
